export default {
  state: {
    paymentCouponList: {},
    currentCoupon: null,
    currentSpec_id: null
  },
  mutations: {
    clearCoupon(state){
      state.paymentCouponList = {}
      state.currentCoupon = null
      state.currentSpec_id = null
    },
    setCouponList(state, value) {
      state.paymentCouponList = value
    },
    setCouponUsed(state, value) {
      state.paymentCouponList[value.id].usedSpecId = value.spec_id
    },
    setCurrentCoupon(state, value) {
      state.currentCoupon = value
    },
    setCurrentSpec_id(state, value) {
      state.currentSpec_id = value
    }
  },
  actions: {
    couponMarking({ state, commit }, { commodity }) {
      let coupon = {}
      commodity.forEach(item => {
        item.coupon.forEach(cp => {
          if (!coupon[cp.id]) {
            cp.usedSpecId = -1
            coupon[cp.id] = cp
          }
        })
      })
      commit('setCouponList', coupon)
    }
  }
}
